In [1]:
import numpy as np
import pandas as pd
import collections
import datetime
In [2]:
from read_table import read_table
In [3]:
table = read_table()
In [4]:
table["1"]
Out[4]:
time open high low close volume
0 2019/01/29 10.96 11.07 10.77 11.00 82663112
1 2019/01/30 10.95 11.18 10.86 10.95 71200104
2 2019/01/31 10.98 11.20 10.94 11.10 83162272
3 2019/02/01 11.20 11.25 10.96 11.20 101427008
4 2019/02/11 11.08 11.21 10.97 11.21 80193664
... ... ... ... ... ... ...
275 2020/03/20 12.40 12.68 12.26 12.52 157835296
276 2020/03/23 12.00 12.35 11.93 12.15 107111360
277 2020/03/24 12.40 12.68 12.27 12.61 118020024
278 2020/03/25 12.88 13.07 12.70 12.87 113695776
279 2020/03/26 12.87 12.87 12.87 12.87 0

280 rows × 6 columns

In [5]:
for i in range(1, 11):
    table[str(i)]['date'] = pd.to_datetime(table[str(i)]['time'], format = "%Y/%m/%d", errors = 'coerce')
In [6]:
for i in range(1, 11):
    temp = table[str(i)]["time"].apply(lambda x: x.split("/"))
    temp = np.array(temp)
    demp = []
    for j in range(0, temp.shape[0]):
        temp[j][0] = str(int(temp[j][0]))
        temp[j][1] = str(int(temp[j][1]))
        temp[j][2] = str(int(temp[j][2]))
        demp.append("/".join(temp[j]))
    table[str(i)]["date"] = demp
In [7]:
table["1"]
Out[7]:
time open high low close volume date
0 2019/01/29 10.96 11.07 10.77 11.00 82663112 2019/1/29
1 2019/01/30 10.95 11.18 10.86 10.95 71200104 2019/1/30
2 2019/01/31 10.98 11.20 10.94 11.10 83162272 2019/1/31
3 2019/02/01 11.20 11.25 10.96 11.20 101427008 2019/2/1
4 2019/02/11 11.08 11.21 10.97 11.21 80193664 2019/2/11
... ... ... ... ... ... ... ...
275 2020/03/20 12.40 12.68 12.26 12.52 157835296 2020/3/20
276 2020/03/23 12.00 12.35 11.93 12.15 107111360 2020/3/23
277 2020/03/24 12.40 12.68 12.27 12.61 118020024 2020/3/24
278 2020/03/25 12.88 13.07 12.70 12.87 113695776 2020/3/25
279 2020/03/26 12.87 12.87 12.87 12.87 0 2020/3/26

280 rows × 7 columns

In [8]:
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use("seaborn")
In [9]:
def print_k_line():
    for i in range(1, 11):
        opens = [q for q in table[str(i)]["open"]]
        high = [q for q in table[str(i)]["high"]]
        low = [q for q in table[str(i)]["low"]]
        close = [q for q in table[str(i)]["close"]]
        # turnover = [q/10000000 for q in table["1"]["turnover"]]
        dates = [datetime.datetime.strptime(q ,"%Y/%m/%d") for q in table[str(i)].date]

        fig = plt.figure(figsize=(20,10), dpi=300)
        ax = fig.add_subplot(111)
        ax.plot_date(dates, opens, color='b',linestyle='-',marker='o', label='open')
        ax.plot_date(dates, close, color='r',linestyle='-',marker='o', label='close')
        ax.plot_date(dates, high, color='g',linestyle='--',marker='v', label='high')
        ax.plot_date(dates, low, color='coral',linestyle='--',marker='v', label='low')
        # ax.plot_date(dates, turnover, color='black',linestyle='-',marker='.', label='volume')
        plt.title("")
        plt.legend()
        fig.autofmt_xdate() 
        plt.show()
In [10]:
print_k_line()
/opt/anaconda3/lib/python3.7/site-packages/pandas/plotting/_matplotlib/converter.py:103: FutureWarning: Using an implicitly registered datetime converter for a matplotlib plotting method. The converter was registered by pandas on import. Future versions of pandas will require you to explicitly register matplotlib converters.

To register the converters:
	>>> from pandas.plotting import register_matplotlib_converters
	>>> register_matplotlib_converters()
  warnings.warn(msg, FutureWarning)
In [ ]: